package org.lee.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * TestServerInitializer
 * http初始化器
 *
 * @author dralee
 * @date 2022-01-03 17:47:19
 **/
public class TestServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        System.out.println("initialize..." + socketChannel);
        // 向管道加入处理器
        ChannelPipeline pipeline = socketChannel.pipeline();
        // 加入netty 提供的httpServerCodec codec => [coder- decoder]
        // 1.HttpServerCodec 是netty提供的http编码解码器
        pipeline.addLast("MyHttpServerCodec", new HttpServerCodec());
        // 2.增加一个自定义的handler
        pipeline.addLast("MyTestHttpServerHandler", new TestHttpServerHandler());
    }
}
